package com.example.restful01.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.restful01.model.Book;
import com.example.restful01.model.Reservation;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ReservationMapper extends BaseMapper<Reservation> {
    @Delete("DELETE FROM Reservation WHERE reader_id = #{readerId} AND book_id = #{bookId} ")
    int deleteBorrows(  @Param("readerId") Integer readerId,
                       @Param("bookId") Integer bookId);
    @Insert("INSERT INTO `reservation` (date, book_id, book_name, reader_id, reader_name, author, status)\n" +
            "SELECT \n" +
            "    CURRENT_TIMESTAMP AS date,\n" +
            "    b.id,\n" +
            "    b.book_name,\n" +
            "    u.reader_id,\n" +
            "    u.reader_name,\n" +
            "    b.author,\n" +
            "    #{status}\n" +
            "FROM \n" +
            "    `book` b\n" +
            "JOIN \n" +
            "    `user` u ON 1 = 1\n" +
            "WHERE \n" +
            "    b.id = #{id} AND u.reader_id = #{readerId};")
    int addReserve(Reservation reservation);
    @Select("select * from reservation where reader_id = #{readerId}")
    List<Reservation> initReserve(Integer readerId);
}
